require(['../config/requireconfig'], function (config) {
	//根据需要添加
	require(['zepto', 'common/mcommon'], function ($, com) {
		com.init();
		var pageLogic = new PageLogic($, com);
		pageLogic.init();

	});
});
// function back(type) {

// };
var PageLogic = function ($, com) {
	return {
		init: function () {
			var _this = this;
			var brandName = com.utils().urlParam("brandName");
			var modelName = com.utils().urlParam("modelName");
			if (!brandName || !modelName) {

				com.utils().windowJump();
			}
			$("#brandName").text(com.utils().urlParam("brandName") || "");
			$("#modelName").text(com.utils().urlParam("modelName") || "");
			$("#breadBrandName").text(com.utils().urlParam("brandName") || "");
			$("#breadModelName").text(com.utils().urlParam("modelName") || "");
			_this.initData();
			// _this.initVichileData();
			_this.bindEvent();
		},
		bindEvent: function () {
			var _this = this;
			$("#selvol").on("change", function () {
				_this.initVichileData();
			});
			$('.back').on("click", function () {
				com.utils().windowJump("prodGas.htm");

			})
			$('#backYear').on("click", function () {
				$('#table2').hide()
				$('#table1').show()
				$('#backYear').hide()

			})

		},
		params: function () {
			var _this = this;
			var obj =
				`brand=${com.utils().urlParam("brandName")}&
				vehicletype=${com.utils().urlParam("modelName")}`
				;
			return obj;
		},
		noString: function (string) {
			if (!string) {
				return "-";
			}
			return string;
		},
		initData: function () {
			var _this = this;
			com.ajax({
				url: "/getByvehicletype.json",
				data: _this.params(),
				success: function (res) {
					let paramsList = res.data
					let html = ''

					$(paramsList).each(function (idx, obj) {
						let displacementL = _this.noString(this.displacementL)
						html += "<tr tg='" + this.vehiclDate + "'displacementL='" + this.displacementL + "'>";
						html += "<td>" + this.vehiclDate + "</td>";
						html += "<td>" + displacementL + "</td>";
						html += "</tr>";
					});
					let ths = '<tr><th style="width:50%">年份</th>';
					ths += '<th style="width:50%">排量（L）</th>';
					$("#table1").find("thead").html(ths);
					$("#table1").find("tbody").html(html);
					$("#table1 tbody tr").click(function () {
						let vehiclDate = $(this).attr('tg');
						let displacementL = $(this).attr('displacementL');
						console.log(1111)
						$("#backYear span").text(vehiclDate)
						$('#backYear').css('display', "flex")
						$('.title .txt').text('变速器选择');
						let data = `brand=${com.utils().urlParam("brandName")}&
						vehicletype=${com.utils().urlParam("modelName")}&
						vehiclDate=${vehiclDate}&
						displacementL=${displacementL}`
						com.ajax({
							url: "/getInfo.json",
							data: data,
							success: function (res) {
								let paramsList = res.data
								let html = ''
								$(paramsList).each(function (idx, obj) {
									html += "<tr displacementL='" + this.displacementL + "'transmissionType='" + this.transmissionType + "'stalls='" + this.stalls + "'transmissionDescription='" + this.transmissionDescription + "'>";
									html += "<td>" + this.transmissionType + "</td>";
									html += "<td>" + this.stalls + "</td>";
									html += "<td>" + this.transmissionDescription + "</td>";
									html += "</tr>";
								});
								let ths = '<tr><th style="width:33%">变速器类型</th>';
								ths += '<th style="width:33%">档位数</th>';
								ths += '<th style="width:33%">变速器描述</th>';
								$("#table2").find("thead").html(ths);
								$("#table2").find("tbody").html(html);
								$("#table2").show()
								$("#table1").hide()
								$("#table2 tbody tr").click(function () {
									let brandName = com.utils().urlParam("brandName");
									let modelName = com.utils().urlParam("modelName");
									let vehiclDate = $("#backYear span").text();
									let displacementL = $(this).attr('displacementL');
									let transmissionType = $(this).attr('transmissionType');
									let stalls = $(this).attr('stalls');
									let transmissionDescription = $(this).attr('transmissionDescription');
									console.log(vehiclDate, displacementL, transmissionType, stalls, transmissionDescription)
									com.utils().windowJump(`prodGasDetail2.htm?brandName=${brandName}&modelName=${modelName}&vehiclDate=${vehiclDate}&displacementL=${displacementL}&transmissionType=${transmissionType}&stalls=${stalls}&transmissionDescription=${transmissionDescription}`);

								})
							}
						});
					})
				}
			});
		},
	}
}